package org.acb.sgp.dao.impl;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.acb.sgp.beans.CategoriaLocacion;
import org.acb.sgp.dao.CategoriaLocacionDao;
import org.acb.sgp.factory.ConnectionFactory;

public class CategoriaLocacionDaoImpl implements CategoriaLocacionDao {

    private Connection con;
    private CallableStatement cs;
    private ResultSet rs;

    private Connection getConnection() throws SQLException {
        return ConnectionFactory.getInstance().getConnection();
    }

    @Override
    public void registrarCategoria(CategoriaLocacion categoria) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void eliminarCategoria(CategoriaLocacion categoria) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public CategoriaLocacion buscarCategoriaPorCodigo(Integer codCategora) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<CategoriaLocacion> listaCategorias() {
        List<CategoriaLocacion> categorias = new ArrayList<CategoriaLocacion>();
        try {
            String sql = "{Call ListarCategoriasLocacion()}";
            con = getConnection();
            cs = con.prepareCall(sql);
            rs = cs.executeQuery();
            while (rs.next()) {
                categorias.add(llenar(rs));
            }
        } catch (SQLException ex) {
            Logger.getLogger(CategoriaLocacionDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            ConnectionFactory.closing(rs, cs, con);
        }
        return categorias;
    }
    
    private CategoriaLocacion llenar(ResultSet rs) throws SQLException {
        CategoriaLocacion categoria = new CategoriaLocacion();
        categoria.setCodCategoria(rs.getInt("codCategoria"));
        categoria.setNomCategoria(rs.getString("nomCategoria"));
        return categoria;
    }

}
